import { assert, beforeAll, describe, test } from 'vitest';
import { CHECK_MODE, testCaseCheck } from '../common/testCommon';
import ConsistentIndexedObjectStyleDsl from '../../../../src/checker/dsl/ConsistentIndexedObjectStyleDsl';
import path from 'path';
import { CheckEntry, Rule } from '../../../../src/Index';

let realPath: string = '';
let checkEntry: CheckEntry;

beforeAll(async () => {
  const rule: Rule = new Rule('');
  checkEntry = await testCaseCheck(
    './test/unittest/sample/ConsistentIndexedObjectStyleDsl',
    rule,
    CHECK_MODE.FILE2CHECK,
    ConsistentIndexedObjectStyleDsl,
    false,
    true
  );
  realPath = checkEntry.scene.getRealProjectDir();
});

describe('ConsistentIndexedObjectStyleDslTest', () => {
  test('ConsistentIndexedObjectStyleDslTest_001', () => {
    const detectFile = path.join(realPath, 'ConsistentIndexedObjectStyleDslReport.ts');
    const expectReportList = ['1%10'];
    const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
    assert.isDefined(detectFileReport, 'The file path is error.');
    assert.equal(detectFileReport?.issues.length, expectReportList.length, 'The number of reported line is different from the expected number of line.');
    detectFileReport?.issues.forEach((issue, index) => {
      assert.include(issue.defect.fixKey, expectReportList[index], `The ${index} fixKey is not expected.`);
    });
  });

  test('ConsistentIndexedObjectStyleDslTest_002', () => {
    const detectFile = path.join(realPath, 'ConsistentIndexedObjectStyleDslNoReport.ts');
    const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
    assert.equal(detectFileReport?.issues.length, 0, 'The number of reported line should be 0.');
  });
});
